import { Body, Controller, Delete, Get, Post, Put } from '@nestjs/common'
import { BindService } from './bind.service'
@Controller('bind')
export class BindController {
    constructor(private readonly BindService: BindService) { }

    @Get()
    get() {
        return {
            code: 200,
            msg: "获取成功"
        }
    }

    @Post('addBind')
    async addBind(@Body() body: any) {
        this.BindService.addBind(body)
        return {
            code: 200,
            msg: "添加成功"
        }
    }

    @Post("getBind")
    async getBind(@Body() body: any) {
        console.log(body)
        const { shopName } = body;
        let searchList = [];
        if (shopName) {
            searchList.push({ bindShop: shopName });
        }


        let data = await this.BindService.getBind(searchList)
        let data2 = await this.BindService.getBind([])

        let bindNameList = [{
            value: '',
            label: '请选择',
        }]
        
        data2.forEach(item => {
            bindNameList.push({ value: item.bindName, label: item.bindName})
        })
        return {
            code: 200,
            msg: "查询成功",
            data,
            bindNameList
        }
    } 

    @Put("updateBind") 
    async updateBind(@Body() body: any) {
        this.BindService.updateBind(body)
        return {
            code: 200,
            msg: "修改成功" 
        }
    } 
    @Put("updateBindStatus")
    async updateBindStatus(@Body() body: any) {
        const { id } = body;
        if(id === 1){
            this.BindService.updateStatus(body)
        }else if(id === 2){
            this.BindService.updateStatus2(body)
        }
        return {
            code: 200,
            msg: "修改成功"
        }
    }

    @Delete("deleteBind")
    async deleteBind(@Body() body: any) {
        this.BindService.deleteBind(body)
        return {
            code: 200,
            msg: "删除成功"
        }
    }

}
